package org.spolo.android.show;

import org.spolo.android.adapter.UiListener;
import org.spolo.android.bean.GestureType;
import org.spolo.android.enventmanager.EventHandlerInterface;
import org.spolo.android.nodetree.Stage;
import org.spolo.android.shape.Circle;
import org.spolo.android.shape.Rectangle;
import org.spolo.android.shape.StageView;
import org.spolo.android.tween.FloatInterpolate;
import org.spolo.android.util.ContextManager;

import android.app.Activity;
import android.graphics.Color;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.GestureDetector;
import android.view.MotionEvent;

public class Androidshow extends Activity {
	int x = 0;
	int y = 0;
	private GestureDetector detector;
	public static int width;
	public static int height;
	private StageView sv;
	private Stage root;
	private Rectangle c;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		ContextManager.getInstance().regContext("Androidshow", this);
		sv = new StageView(this);
		root = Stage.getInstance();
		setContentView(sv);
		// 获取屏幕的宽高
		DisplayMetrics dm = new DisplayMetrics();
		dm = this.getApplicationContext().getResources().getDisplayMetrics();
		width = dm.widthPixels;
		height = dm.heightPixels;
		// AppTopicManager.instance()
		// .topicChanged(AppTopicManager.PRESETATION_360);

		c = new Rectangle(50f, 50f, 100f, 100f);
		Circle cir = new Circle(0f, 0f, 20f);
		cir.getPaint().setColor(Color.RED);

		c.GetEventQueue().addListener(GestureType.onClick, new CirListener());
		c.addChild(cir);
		root.addChild(c);
		detector = new GestureDetector(new UiListener());
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		return detector.onTouchEvent(event);
	}

	@Override
	public void onBackPressed() {
		// 暂时使用强制退出的办法来消除view的残影
		android.os.Process.killProcess(android.os.Process.myPid());
		super.onBackPressed();
	}

	class CirListener implements EventHandlerInterface {

		@Override
		public Object execute(Object parameter) {
			FloatInterpolate fo = new FloatInterpolate(c, 90f, 5000);
			fo.start();
			return null;
		}

	}

}